<template>
  <div class="login">
    <commhead-2 name='注册'/>
    <van-form @submit="onSubmit">
      <div class="iphone">
        <span class="padd_5 font_18">+86</span>
        <span class="padd_5"><van-icon name="arrow-down" /></span>
        <van-field
          v-model="username"
          name="username"
          placeholder="请输入手机号"
          clearable
        />
      </div>
      <div class="iphone code">
        <van-field
          v-model="password"
          type="password"
          name="password"
          placeholder="请输入收到得验证码"
          clearable
        />
        <div class="nowarp">获取验证码</div>
      </div>
      <div style="margin: 20px 20px;">
        <van-button round block  type="warning" native-type="submit" class="btn">登录</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { doRegister } from '_api'
import { Toast } from 'vant'
import Commhead2 from '../../components/Commhead2.vue'
export default {
  data () {
    return {
      username: null,
      password: null
    }
  },
  methods: {
    onSubmit (data) {
      console.log(data)
      doRegister({
        pwd: data.password,
        username: data.username
      }).then(res => {
        if (res.data.code === 0) {
          Toast({
            type: 'success',
            duration: 1000,
            message: res.data.msg,
            onClose: () => {
              this.$router.replace('/login')
            }
          })
        } else {
          Toast.fail(res.data.msg)
        }
      })
    },
    toregist () {
      this.$router.push('/regist')
    }
  },
  components: { Commhead2 }
}
</script>

<style lang="scss" scoped>
.login{
  height: 100vh;
  background-color: white;
  overflow: hidden;
  .van-form{
    margin-top: 50px;
    overflow: hidden;
    .iphone{
      display: flex;
      font-size: 16px;
      align-items: center;
      margin: 10px 20px;
      border-bottom: 1px solid #ccc;
      /deep/.van-field__control{
        font-size: 16px;
      }
      .padd_5{
        padding: 0 5px;
      }
      .font_18{
        font-size: 16px;
      }
    }
    .code{
      margin-bottom: 40px;
      .nowarp{
        white-space: nowrap;
        font-size: 12px;
        color: #999;
        padding: 5px 20px;
        border-left: 1px solid #999
      }
    }
  }
}
</style>
